package com.example.x3day04.model;

import android.annotation.SuppressLint;

import com.example.x3day04.base.BaseCallBack;
import com.example.x3day04.base.BaseModel;
import com.example.x3day04.base.BaseObserver;
import com.example.x3day04.bean.Bean;
import com.example.x3day04.bean.NaviBean;
import com.example.x3day04.net.ApiService;
import com.example.x3day04.presenter.MainPresenter;
import com.example.x3day04.util.HttpUtile;
import com.example.x3day04.util.RxUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.ResourceSubscriber;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainModel extends BaseModel {

    @SuppressLint("CheckResult")
    public void getData(final BaseCallBack<Bean> callBack) {
//        ResourceSubscriber<Bean> resourceSubscriber = new Retrofit.Builder()
//                .baseUrl(ApiService.FULIURL)
//                .addConverterFactory(GsonConverterFactory.create())
//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
//                .build()
//                .create(ApiService.class)
//                .getData()
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribeWith(new ResourceSubscriber<Bean>() {
//                    @Override
//                    public void onNext(Bean bean) {
//                        callBack.onSuccess(bean);
//                    }
//
//                    @Override
//                    public void onError(Throwable t) {
//                        callBack.onFail(t.getMessage());
//                    }
//
//                    @Override
//                    public void onComplete() {
//
//                    }
//                });
//        addDisposable(resourceSubscriber);
//        addDisposable(
//                HttpUtile.getInstance()
//                            .getWanService()
//                            .getNavi()
//                            .compose(RxUtils.<NaviBean>rxSchedulerHelper())
//                            .subscribeWith(new ResourceSubscriber<NaviBean>() {
//                                @Override
//                                public void onNext(NaviBean naviBean) {
//
//                                }
//
//                                @Override
//                                public void onError(Throwable t) {
//
//                                }
//
//                                @Override
//                                public void onComplete() {
//
//                                }
//                            })
//
//        );
//        addDisposable(
//                HttpUtile.getInstance()
//                            .getWanService()
//                            .getNavi()
//                            .compose(RxUtils.<NaviBean>rxSchedulerHelper())
//                            .subscribeWith(new BaseObserver<NaviBean>() {
//                                @Override
//                                public void onNext(NaviBean naviBean) {
//
//                                }
//                            })
//        );
        addDisposable(
                HttpUtile.getInstance()
                        .getApiService()
                        .getData()
                        .compose(RxUtils.<Bean>rxSchedulerHelper())
                        .subscribeWith(new BaseObserver<Bean>() {
                            @Override
                            public void onNext(Bean bean) {
                                callBack.onSuccess(bean);
                            }
                        })
        );
    }
}
